# -*- coding: utf-8 -*-
# @Author  : Pony.guan
# @Time    : 2021/11/8 下午2:23
# Description: 服务启动（主流程）

import os
import sys
import tornado.ioloop
import tornado.web
from tornado.options import define, options

from config import LOG, Debug
from urls import urls


class Application(tornado.web.Application):
    def __init__(self, handlers):
        self.log = LOG
        tornado.web.Application.__init__(self, handlers, debug=Debug, xsrf_cookies=False)


def make_app():
    return Application(urls)


if __name__ == "__main__":
    base_dir = os.path.dirname(os.path.abspath(__file__))
    sys.path.append(base_dir)
    define("port", default=8889, help="run on the given port", type=int)
    options.parse_command_line()
    app = make_app()
    app.listen(options.port)
    tornado.ioloop.IOLoop.current().start()
